package controller;

import controller.actions.Action;
import controller.actions.DefaultAction;
import controller.actions.LoginAction;
import controller.actions.RegistrationAction;

import java.util.HashMap;
import java.util.Map;

public class ActionFactory {
    protected Map<String, Class<?>> map = defaultMap();

    public Action create(String actionName) {
        Class<?> actionClass = (Class<?>) map.get(actionName);
        Action actionInstance = null;

        if (actionClass == null){
            return actionInstance = new DefaultAction();//class.newInstance
        }else{
            try {
                actionInstance = (Action) actionClass.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return actionInstance;
    }

    protected Map<String, Class<?>> defaultMap() {
        Map<String, Class<?>> map = new HashMap<String, Class<?>>();
        map.put("loginAction", LoginAction.class);
        map.put("defaultAction", DefaultAction.class);
        map.put("registrationAction", RegistrationAction.class);
        return map;
    }
}
